<template>
    <div class="search-history">
        <div class="flex-space-between">
            <h1>搜索历史</h1>
            <el-button link style="color: var(--color-text-l)" @click="search.remove()">清空</el-button>
        </div>
        <div class="search-history__content">
            <span class="tag-container" v-for="(item, index) in historyInstance" :key="index">
                <i class="icon-close" @click="search.delete(index)"></i>
                <span>
                    {{ item }}
                </span>
            </span>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { storeToRefs } from 'pinia'
import useStore from '@/store'
const { search } = useStore()
const { historyInstance } = storeToRefs(search)
const remove = () => {
    console.log('remove')
}
</script>

<style lang="less" scoped>
.search-history {
    h1 {
        font-weight: 700;
        color: var(--color-text-s);
    }

    .search-history__content {
        display: flex;
        flex-wrap: wrap;
        padding-top: 10px;

        >span.tag-container {
            padding: 5px 15px 5px;
            margin: 0 10px 10px 0;
            cursor: pointer;
            background-color: var(--color-gray-p);
            .border-radius;
            position: relative;

            &:hover {
                color: var(--color-primary);

                .icon-close {
                    display: block;
                }
            }

            .icon-close {
                display: none;
                font-size: var(--font-size-medium);
                position: absolute;
                top: -3px;
                right: -3px;
                color: var(--color-text-l);
            }
        }
    }
}</style>